package bt19022014_congty;

import java.util.List;

public class CongTy {
	private String ten;
	private DiaChi diaChi;
	private List<NhanVien> dsNV;
	//Phuong thuc khoi tao ko tham so
	public CongTy(){
		ten = null;
		diaChi = new DiaChi();
		dsNV = null;
	}
	
	//Phuong thuc khoi tao co tham so
	public CongTy(String ten, DiaChi diaChi, List<NhanVien> dsNV){
		this.ten = ten;
		this.diaChi = diaChi;
		this.dsNV = dsNV;
	}
	
	//Phuong thuc them NV moi vao cong ty, kiem tra msnv da ton tai hay chua truoc khi them
	public boolean themNV(NhanVien nv){
		for (NhanVien a : dsNV){
			if (a.ktraMSNV(nv.getMsNV())){
				System.out.println("Khong the them nhan vien nay!");
				return false;
			}
		}
		dsNV.add(nv);
		System.out.println("Them nhan vien thanh cong!");
		return true;
	}
	
	//Phuong thuc tinh tong luong cac nhan vien trong cong ty trong 1 nam
	public double tinhTongLuong (){
		double tongLuong = 0;
		for (NhanVien a : dsNV){
			tongLuong += a.tinhLuong()*12;
		}
		return tongLuong;
	}
	
	//Phuong thuc xoa mot NV trong cong ty, truoc khi xoa kiem tra xem msnv co ton tai hay ko?
	public boolean xoaNV(NhanVien nv){
		for (NhanVien a : dsNV){
			if (a.ktraMSNV(nv.getMsNV())){
				dsNV.remove(a);
				System.out.println("Da xoa thanh cong nhan vien khoi danh sach!");
				return true;
			}
		}
		System.out.println("Nhan vien khong ton tai! Khong the xoa!");
		return false;
	}
	
	//Phuong thuc loc ra danh sach cac NV co muc luong nho hon 1 so nhap vao
	public List<NhanVien> dsNVTheoLuong(double luong){
		List<NhanVien> dsIn = null;
		for(NhanVien a : dsNV){
			if(a.ssanhLuong(luong)){
				dsIn.add(a);
			}
		}
		return dsIn;
	}
	
	//Phuong thuc in ra danh sach cac NV
	public void inDSNV(){
		for(NhanVien a: dsNV){
			a.inNhanVien();
			System.out.println("-------------------------------------");
		}
	}
	
}
